package engine.light;

import engine.shader.Shader;

public class PointLight extends Light implements Comparable<PointLight> {
	
	private float[] position;
	
	private float constantAttenuation;
	private float linearAttenuation;
	private float quadraticAttenuation;
	
	private double priority;
	
	public PointLight() {
		super();
		
		position = new float[]{0, 0, 0, 1};
		
		constantAttenuation = 1;
	}
	
	public float[] getPosition() {
		return position;
	}
	
	public void setPosition(float x, float y, float z) {
		position[0] = x;
		position[1] = y;
		position[2] = z;
	}
	
	public void setPosition(float[] position) {
		setPosition(position[0], position[1], position[2]);
	}

	public float getConstantAttenuation() {
		return constantAttenuation;
	}

	public void setConstantAttenuation(float constantAttenuation) {
		this.constantAttenuation = constantAttenuation;
	}

	public float getLinearAttenuation() {
		return linearAttenuation;
	}

	public void setLinearAttenuation(float linearAttenuation) {
		this.linearAttenuation = linearAttenuation;
	}

	public float getQuadraticAttenuation() {
		return quadraticAttenuation;
	}

	public void setQuadraticAttenuation(float quadraticAttenuation) {
		this.quadraticAttenuation = quadraticAttenuation;
	}
	
	@Override
	public void apply(Shader shader, int lightSource) {
		super.apply(shader, lightSource);
		
		shader.sendUniform1f("lights[" + lightSource + "].constantAttenuation", constantAttenuation);
		shader.sendUniform1f("lights[" + lightSource + "].linearAttenuation", linearAttenuation);
		shader.sendUniform1f("lights[" + lightSource + "].quadraticAttenuation", quadraticAttenuation);	
		shader.sendUniform1f("lights[" + lightSource + "].spotCutoff", 180);
		shader.sendUniform4f("lights[" + lightSource + "].position", position);
	}
	
	public void setPriority(double priority) {
		this.priority = priority;
	}

	@Override
	public int compareTo(PointLight p) {
		if(priority > p.priority) {
			return 1;
		} else {
			return -1;
		}
	}
}
